﻿// MIT License
// 开源地址：https://gitee.com/co1024/AbcMvc
// Copyright (c) 2021-2023 1024
// Abc.Mvc=Furion+EF+SqlSugar+Pear layui admin.

using Furion.Logging;

namespace Abc.Utils.Module.Elasticsearch;
/// <summary>
/// 使用es写日志
/// </summary>
public class ESLoggingWriter : IDatabaseLoggingWriter
{
    private readonly IEsLoggingProvider _esLoggingProvider;

    public ESLoggingWriter(IEsLoggingProvider esLoggingProvider)
    {
        _esLoggingProvider = esLoggingProvider;
    }

    public async void Write(LogMessage logMsg, bool flush)
    {
        var logentity = logMsg.Adapt<EsFurionLoggingModel>();
        //var logentity = new EsFurionLoggingModel();
        //logentity.logName = logMsg.LogName;
        //logentity.logLevel = logMsg.LogLevel.ToString();
        //logentity.eventId = logMsg.EventId.ToJson();
        //logentity.message = logMsg.Message;
        //logentity.exception = logMsg.Exception.ToStringEx();
        //logentity.context = logMsg.Context.ToJson();
        //logentity.state = logMsg.State.ToJson(); 
        //logentity.logDateTime= logMsg.LogDateTime.ToString("yyyy-MM-dd HH:mm:ss.fffff");
        //logentity.threadId = logMsg.ThreadId;
        //logentity.useUtcTimestamp = logMsg.UseUtcTimestamp;
        //logentity.traceId = logMsg.TraceId;

        await _esLoggingProvider.Write(logentity,"AbcLogs");
    }
}
